﻿/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-02-24 11:10
 * 描  述：对象类型
 */
var acceptClick;
var keyValue = request('keyValue');
var UpObjectTypeID = request('UpObjectTypeID');
var ProjectId = request('ProjectId');
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.bind();
            page.initData();
        },
        bind: function () {
            $('#UpObjectTypeID').lrselect({
                url: top.$.rootUrl + '/ZZDT_EC/ec_objecttype/GetTreeData',//获取数据地址
                param: { ProjectId: ProjectId, isShowCheck: false, ObjectTypeID: keyValue }, //请求后台参数
                type: 'tree',//数据展示类型：                1.default：普通；2.tree：树形数据；3. treemultiple：树形多选；multiple：普通多选
                allowSearch: true,
                maxHeight: 225
            }).lrselectSet(UpObjectTypeID);//lrselectSet获取下拉框选择的值，传入UpObjectTypeID

            $('#DefaultLayoutLibFileID').lrselect({
                url: top.$.rootUrl + '/ZZDT_EC/ec_library_file/GetTreeDataByObjectType',//获取数据地址
                param: { ProjectId: ProjectId, ObjectTypeID: keyValue }, //请求后台参数
                type: 'tree',//数据展示类型：                1.default：普通；2.tree：树形数据；3. treemultiple：树形多选；multiple：普通多选
                allowSearch: true,
                maxHeight: 225
            }).lrselectSet(DefaultLayoutLibFileID);//lrselectSet获取下拉框选择的值，传入UpObjectTypeID
        },
        initData: function () {
            if (!!keyValue) {
                $.lrSetForm(top.$.rootUrl + '/ZZDT_EC/ec_objecttype/GetFormData?keyValue=' + keyValue + "&ProjectId=" + ProjectId, function (data) {
                    for (var id in data) {
                        if (!!data[id] && data[id].length > 0) {
                            $('#' + id).jfGridSet('refreshdata', data[id]);
                        }
                        else {
                            $('[data-table="' + id + '"]').lrSetFormData(data[id]);
                        }
                    }
                });
            }
        }
    };
    // 保存数据
    acceptClick = function (callBack) {
        var formData = $('#form').lrGetFormData();
        if (!formData.OrderID) {
            $('#OrderID').val('-1');
            formData.OrderID = -1;
        }
        if (!$('#form').lrValidform()) {
            return false;
        }
        //文字特殊字符及最大长度检测
        if (!verify()) {
            return false;
        }

        //如果勾选了对象类型名称(英文)就必须输入
        formData.IsSerialNumber = Number(formData.IsSerialNumber);
        if (formData.IsSerialNumber == 1) {
            if (!formData.ObjectTypeNameEN) {
                $.lrValidformMessage($("#ObjectTypeNameEN"), "对象类型名称(英文)必须输入");
                $('#ObjectTypeNameEN').click();
                return false;
            }
        }
        if (!formData.UpObjectTypeID) {
            formData.UpObjectTypeID = '0';
        }
        var postData = {
            strEntity: JSON.stringify(formData),
            ProjectId: ProjectId
        }
        $.lrSaveForm(top.$.rootUrl + '/ZZDT_EC/ec_objecttype/SaveForm?keyValue=' + keyValue, postData, function (res) {//感觉url里只能传一个参数，剩下的必须要以postdata方式
            // 保存成功后才回调
            if (!!callBack) {
                callBack();
            }
        });
    };
    page.init();
}
//文字特殊字符及最大长度检测
function verify() {
    var msg = checkStr($("#ObjectTypeName").val(), 200);
    if (msg) {
        $.lrValidformMessage($("#ObjectTypeName"), msg);
        $('#ObjectTypeName').click();
        return false;
    }
    msg = checkStr($("#ObjectTypeNameEN").val(), 200);
    if (msg) {
        $.lrValidformMessage($("#ObjectTypeNameEN"), msg);
        $('#ObjectTypeNameEN').click();
        return false;
    }
    return true;
}